﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PKURG.CostSplit.Business.QueryBase;

namespace PKURG.CostSplit.Business
{
    public class Sys_Admin
    {
        public static List<dynamic> GetCanRelationCompanyList(string name)
        {
            return ExecuteQuery.GetList(
                new QueryBase.QueryInfo()
                {
                    ProcName = "usp_n_GetCanRelationCompanyList",
                    Params = { name }
                });
        }
        public static List<dynamic> GetRelatedCompanyList(string name)
        {
            return ExecuteQuery.GetList(
                new QueryBase.QueryInfo()
                {
                    ProcName = "usp_n_GetRelatedCompanyList",
                    Params = { name }
                });
        }

        public static List<dynamic> GetUserList()
        {
            return ExecuteQuery.GetList(
                new QueryBase.QueryInfo()
                {
                    ProcName = "ups_GetUserList",
                    Params = {}
                });
        }

        public static List<dynamic> GetUserList(string name)
        {
            List<dynamic> ls= ExecuteQuery.GetList(
                new QueryBase.QueryInfo()
                {
                    ProcName = "ups_GetUserList",
                    Params = {}
                });
            if (string.IsNullOrEmpty(name))
            {
                return ls;
            }
            return ls.Where(x => x.Name.Replace("founder\\","").Contains(name) || x.DisplayName.Contains(name)).ToList();
        }

        public static List<dynamic> GetUserListForRole(string name)
        {
            List<dynamic> ls = GetUserList(name);
            return ls.Where(x => x.PType == "1").ToList();
        }

        public static dynamic GetUserInfo(string name)
        {
            List<dynamic> infos= ExecuteQuery.GetList(
                new QueryBase.QueryInfo()
                {
                    ProcName = "ups_GetUserInfo",
                    Params = { name }
                });
            if (infos.Count>0)
            {
                return infos[0];
            }
            return null;
        }

        public static int UpdateUserInfo(string name,string displayName,int pType,int rwType)
        {
            return QueryBase.CustomProcess.ExecuteProcNonQuery("ups_UpdateUserInfo",
                new Object[] {name,displayName,pType,rwType });
        }

        public static int Relation(string name, string companyName)
        {
            return QueryBase.CustomProcess.ExecuteProcNonQuery("usp_n_AdminRelation",
                new Object[] { name, companyName });
        }
        public static int UnRelation(string name, string companyName)
        {
            return QueryBase.CustomProcess.ExecuteProcNonQuery("usp_n_UnAdminRelation",
                new Object[] { name, companyName });
        }
    }
}
